<?php
	function restr($str){
		$str = html_entity_decode($str);
		$folder_char = array('/','\\','?','*',':','"','<','>','|','!',' ',"\b","\t",'《','》');
		str_replace($folder_char,'_',$str);
		return $str;
	}


	set_time_limit(0);
	$base_url = 'http://www.fxdm.net/';
	//------------------------
	$url = '1.txt';// 'http://www.fxdm.net/index_53.html';
	//--------------------------------
	
	$content = file_get_contents($url);
	
	$match_str = "/<table width=\"100%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"5\">(.*)<\/table>/isU";
	preg_match_all ($match_str,$content,$array_item);
	//获取图片列表
	$lists = $array_item[1][0];
	//获取某个分类的连接以及名称
	//<td class="list">·<a href="http://www.fxdm.net/200609/18/1158577477d11458.html" target="_blank" title="韩国精美壁纸">韩国精美壁纸</a></td><td>09/18</td>
	$match_str = "/<a href=\"(.*)\" target=\"_blank\" title=\"(.*)\">(.*)<\/a><\/td>/isU";
	preg_match_all ($match_str,$lists,$array_item);
	$links = $array_item[1];
	$names = $array_item[2];
	foreach ($names as $key=>$value) {
//		$names[$key] = substr(trim(restr($value)),0,100);
		$folder_char = array('/','\\','?','*',':','"','<','>','|','!',' ',"\b","\t","《","》",'(',')','！');
		
		$value = html_entity_decode($value);
		$value = substr($value,0,120);
		
		$names[$key] = str_replace($folder_char,'',$value);
		ereg_replace('》','',$names[$key]);
		//preg_replace('/！/isU','',$names[$key]);
//		if (!is_dir("./upload/" . $value)) {
//			@$result = mkdir("./upload/" .$value);
//			if (!$result) {
//				echo "<font color=red>CREATE FOLDER: " . $value . " FAIL!</font><br />";
//				continue;
//			}
//			echo "<font color=blue>NOW IS CREATE FOLDER :" . $value . ",</font><br />";
//		}
//		else {
//			echo "<font color=#6688FF>FOLDER " . $value . "IS EXISTS,</font><br />";
//		}
	}
	
	print_r($names);
	exit;
	
//	
//	
//	
//	
//			if (!is_dir("./upload/" . $name_block[$k])) {
//				@$result = mkdir("./upload/" . $name_block[$k]);
//				if (!$result) {
//					echo "<font color=red>�����ļ���:" . $name_block[$k] . " ʧ��</font><br />";
//					continue;
//				}
//				echo "<font color=blue>�����ļ���:" . $name_block[$k] . ",</font><br />";
//			}
//			else {
//				echo "<font color=#6688FF>�ļ���:" . $name_block[$k] . " �Ѿ�����,</font><br />";
//			}
//			//����ĳ�������ļ������
//			$dir_name = $name_block[$k] . '/';
//			
//			//����ĳ��ͼƬ8Ŀ���вɼ�
//			//<TD bgColor=#000000><A href="/showpic.shtml?pic=/images/comic/2006/07/28/bz/comicqq01.jpg" target=_blank><IMG alt="��ȭ��XI�����8�ˮ׼��ֽ�ղ�"  src="/images/comic/2006/07/28/bz/s/comicqq01.jpg" border=0></A></TD>
//			@$pic_content = file_get_contents($link_block[$k]);
//			//<a href="/a/20060728/000021_18.htm">19</a>ҳ
//			$match_str = "/��(.*)ҳ/isU";
//			preg_match_all($match_str,$pic_content,$pic_nums);
//			$pic_nums = $pic_nums[1][1];
//			$match_str = "/<a href=\"(.*)\">/isU";
//			preg_match_all($match_str,$pic_nums,$pic_links);
//			//��ȡ�÷����µ�����ͼƬ��l��
//			$pic_links = $pic_links[1];
//			foreach ($pic_links as $k=>$v) {
//				//�õ�ĳҳl��
//				$v = $base_url . $v;
//				//��ȡĳҳ������ͼƬl��
//				$match_str = "/<A href=\"\/showpic.shtml\?pic=(.*)\"/isU";
//				@$pic_content2 = file_get_contents($v);
//				preg_match_all($match_str,$pic_content2,$pic);
//				foreach ($pic[1] as $key=>$val) {
//					$val = $base_url . $val;
//					$base = "./upload/" . $dir_name . basename($val);
//					//�������ȡ�˾Ϳ���ֱ�ӷŵ��ļ���������
//					if (!file_exists($base)) {
//						@copy($val,$base);
//						echo '�ļ�<font color= red>' . basename($val) . '</font>�Ѿ�����Ϊ:<font color= red>' . $base . '</font><br />';
//					}
//					else 
//						echo '�ļ�<font color= red>' . basename($val) . '</font>�Ѵ���,�Թ�<br />';
//				}
//			}
//			//��ȡ��ǰҳ�������ͼƬ
//			$match_str = "/<A href=\"\/showpic.shtml\?pic=(.*)\"/isU";
//			preg_match_all($match_str,$pic_content,$pic);
//			foreach ($pic[1] as $key=>$val) {
//				$val = $base_url . $val;
//				$base = "./upload/" . $dir_name . basename($val);
//				//�������ȡ�˾Ϳ���ֱ�ӷŵ��ļ���������
//				if (!file_exists($base)) {
//					@copy($val,$base);
//					echo '�ļ�<font color= red>' . basename($val) . '</font>�Ѿ�����Ϊ:<font color= red>' . $base . '</font><br />';
//				}
//				echo '�ļ�<font color= red>' . basename($val) . '</font>�Ѵ���,�Թ�<br />';
//			}
//			echo '���: <font color=red>' . substr($dir_name,0,strlen($dir_name) - 1) . '</font>�ɼ����<br />';
//	}
//	echo 'ҳ��: <font color=red>' .$val . '</font>�ɼ����<br />';
//}
?>